<form class="layui-form page-content p-4">
	<h3 class="h3-title">新建需求</h3>
	<table class="layui-table layui-table-form">
		{empty name="$project_id"}
		<tr>
			<td class="layui-td-gray">需求主题<font>*</font></td>
			<td colspan="3">
				<input type="text" name="title" lay-verify="required" lay-reqText="请输入需求主题" placeholder="请输入需求主题" class="layui-input" value="">
			</td>
			<td class="layui-td-gray">关联项目</td>
			<td>
				<select id="projectId" name="project_id">
					<option value="">请选择</option>
					{volist name=":get_project()" id="v"}
					<option value="{$v.id}">{$v.name}</option>
					{/volist}
				</select>
			</td>
		</tr>
		{else/}
		<tr>
			<td class="layui-td-gray">需求主题<font>*</font></td>
			<td colspan="5">
				<input type="text" name="title" lay-verify="required" lay-reqText="请输入需求主题" placeholder="请输入需求主题" class="layui-input" value="">
				<input type="hidden" name="project_id" value="{$project_id}">
			</td>
		</tr>
		{/empty}
		<tr>
			<td class="layui-td-gray">负责人<font>*</font></td>
			<td>
				<input type="hidden" name="director_uid" lay-verify="required" readonly lay-reqText="请选择需求负责人" value="">
				<input type="text" name="director_name" placeholder="请选择需求负责人" readonly class="layui-input" value="">
			</td>
			<td class="layui-td-gray">起止日期<span style="color: red">*</span></td>
			<td id="date">
				<div class="layui-input-inline">
					<input type="text" id="start_time" name="start_time" readonly lay-verify="required" lay-reqText="请选择开始时间" placeholder="请选择时间" class="layui-input" value="">
				</div>
				-
				<div class="layui-input-inline">
					<input type="text" id="end_time" name="end_time" readonly lay-verify="required" lay-reqText="请选择结束时间" placeholder="请选择时间" class="layui-input" value="">
				</div>
			</td>

			<td class="layui-td-gray">优先级<span style="color: red">*</span></td>
			<td>
				<select id="projectId" name="priority">
					<option value="1" selected>低</option>
					<option value="2">中</option>
					<option value="3">高</option>
					<option value="4">紧急</option>
				</select>		
			</td>			
		</tr>
	</table>
	<div>
		<div style="padding:10px 0">需求描述<span style="color: red">*</span></div>
		<div>
			<textarea id="mdContent" style="display:none;"></textarea>
			<div id="docContent"></div>
		</div>
	</div>
	<div style="padding: 10px 0">
		<input type="hidden" name="id" value="0" />
		<button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="webform">立即提交</button>
		<button type="reset" class="layui-btn layui-btn-primary">重置</button>
	</div>
</form>

<script>
function openInit() {
	const form = layui.form,
		layer = layui.layer,
		gougu = layui.gougu,
		laydate = layui.laydate,
		dropdown = layui.dropdown,
		employeepicker = layui.employeepicker;
			
	form.render();
	gougu.editor('docContent',480,$('#mdContent').val());
	
	//日期范围
	laydate.render({
		elem: '#date',
		range: ['#start_time', '#end_time']
	});
	
	//关联项目
	form.on('select(product)', function(data){
		console.log(data.value);
		if(data.value==''){
			$('#projectId').html('<option value="">请先选择关联的产品</option>');
			form.render("select");
		}
		else{
			gougu.get("/api/index/get_project",{pid:data.value},function(res){
				let data = res.data;
				if(data.length>0){
					let ops='<option value="">请先选择项目</option>';
					for(let i=0;i<data.length;i++){
						ops+='<option value="'+data[i].id+'">'+data[i].title+'</option>';
					}
					$('#projectId').html(ops);
					form.render("select");
				}
			});
		}
	});	
	
	//选择产品负责人弹窗	
	$('.page-content').on('click','[name="director_name"]',function () {
		var ids=$('[name="director_uid"]').val(),names=$('[name="director_name"]').val();
		employeepicker.init({
			ids:ids,
			names:names,
			department_url: "/api/index/get_department_tree",
			employee_url: "/api/index/get_employee",
			type:0,
			callback:function(ids,names,dids,departments){
				$('[name="director_uid"]').val(ids);
				$('[name="director_name"]').val(names);
			}
		});
	}); 
	
	
	//选择产品评审人弹窗	
	$('.page-content').on('click','[name="team_admin_names"]',function () {
		var ids=$('[name="team_admin_ids"]').val(),names=$('[name="team_admin_names"]').val(),team_admin_id_array=[],team_admin_name_array=[];
		if(ids.length>0){
			team_admin_id_array=ids.split(',');
			team_admin_name_array.split(',');
		}
		employeepicker.init({
			ids:team_admin_id_array,
			names:team_admin_name_array,
			department_url: "/api/index/get_department_tree",
			employee_url: "/api/index/get_employee",
			type:1,
			callback:function(ids,names,dids,departments){
				$('[name="team_admin_ids"]').val(ids);
				$('[name="team_admin_names"]').val(names);
			}
		});
	});
		
    //监听提交
    form.on('submit(webform)', function (data) {
		let callback = function (e) {
			layer.msg(e.msg);
			if (e.code == 0) {
				layui.pageTable.reload();
				setTimeout(function(){
					gougu.close();
				},500);
			}
		}
		gougu.post("/requirements/index/add",data.field,callback);
		return false;
    });
}

</script>